package ScratchPad
{
	import SplineComponent.SplineComponentView;
	
	import flash.display.DisplayObject;
	
	import mvc.Controller;
	
	import mx.containers.Panel;
	
	import util.Observable;

	public class ScratchPadView extends SplineComponentView
	{
		private var lessonView_object:Object = new Object;
		private var evenPage:Array;
		private var oddPage:Array;
		//private var stage:Sprite;
		private var mainPanel:Panel;
		
		public function ScratchPadView(model:Observable, controller:Controller, lessonView:Object,LessonEditMode:Boolean)
		{
			super(model, controller);
			this.lessonView_object = lessonView;
			initialize();
			super.makePanelDraggable(this.mainPanel);
			super.makePanelResizable();
		}
		
		private function initialize():void
		{
	        mainPanel=new Panel();
	       
			mainPanel.x=500;
			mainPanel.y=200;
			mainPanel.width=500;
			mainPanel.height=530;
			mainPanel.setStyle("backgroundColor","#FBF9F9");
			this.lessonView_object.addChildToStage(mainPanel);
	        
	        
			evenPage=new Array();
			oddPage=new Array();
	
			var  j:oddPagePanel=new oddPagePanel(this,1);
			j.PreviousPage.setVisible(false);
			oddPage.push(j);
			mainPanel.addChild(j);
		}
		public function OpenNextPage(Page:DisplayObject,PNo:uint)
		{
			if(PNo%2==0)
			{
				var  newoddPage:oddPagePanel=new oddPagePanel(this,PNo+1);
				mainPanel.removeChild(Page);
				oddPage.push(newoddPage);
			mainPanel.addChild(newoddPage);
			}
			else
			{
				var  newevenPage:evenPagePanel=new evenPagePanel(this,PNo+1);
				mainPanel.removeChild(Page);
				evenPage.push(newevenPage);
			mainPanel.addChild(newevenPage);
			}
			
		}
		public function OpenPreviousPage(Page:DisplayObject,PNo:uint)
		{
			if(PNo%2==0)
			{
				var  newoddPage:oddPagePanel=oddPage[PNo-2];
				mainPanel.removeChild(Page);
			mainPanel.addChild(newoddPage);
			}
			else
			{
				
				var  newevenPage:evenPagePanel=evenPage[PNo-2];
				mainPanel.removeChild(Page);
			mainPanel.addChild(newevenPage);
			
			}
		}
		
		
		//-----------------------------------------------------communication function-----------------------------------------------//
		override public function update(model:Observable, infoObj_object:Object):void
		{
			var message:String=infoObj_object.message.toString();
			
			switch(message)
			{
				case "mouseUpEvent":
					trace("ScratchPadView------->event:mouseup  infoObj.event :"+infoObj_object.event);
					super.recieveMouseUpEvent(infoObj_object.event);
					break;
			}
		}
	}
}